﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class ServicesSheet_BusinessCardListPs : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent();

            Master.DataSource = WMaster;
          
            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "~/Help/ServicesSheet/名片申请列表.htm";
            master.PageName = "名片申请列表";
            master.PicUrl = "";
            master.IntiBar();
            btnSearch_Click(null, null);
        }
       
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServicesSheet_BusinessCardListPs));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DataCompressed = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = -1;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "ServiceSheet.View_BusCard";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

   
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string Sql = "";
        //非管理员只能查看自已的单据
        if (Srvtools.CliUtils.fGroupID.IndexOf(System.Configuration.ConfigurationManager.AppSettings["FlowAdmin"].ToString()) == -1)
        {
            String wh = " Services_BusinessCard.EmployeeId='" + Convert.ToInt32(Srvtools.CliUtils.fLoginUser).ToString() + "'";
             Sql = wh;
         }
        else
        {
            Sql = "(1=1)";
        }

        string strEmpId = SelUser.EmpName;
        if (strEmpId != "" && strEmpId != string.Empty) Sql = Sql + " And (Employees.EmpName like '%" + strEmpId + "%') ";
        if (QPrinted.SelectedValue != "9") Sql = Sql + " And (Services_BusinessCard.Printed =" + QPrinted.SelectedValue + ")";
        if (QGiven.SelectedValue != "9") Sql = Sql + " And (Services_BusinessCard.Given = " + QGiven.SelectedValue + ")";
        Master.SetWhere(Sql);

        Master.DataBind();
        wgvMaster.DataBind();
    }

    //protected void btnClear_Click(object sender, EventArgs e)
    //{

    //    this.QueryEmp.BindingValue = "";
    //    this.QueryEmp.BindingText = "";
    //    QPrinted.SelectedValue = "9";
    //    QGiven.SelectedValue = "9";
    //    string Sql = "(1=1)";
    //    Master.SetWhere(Sql);
    //    Master.DataBind();
    //    wgvMaster.DataBind();
    //}
    protected void WebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdAdd")
        {

            Response.Redirect("BusinessCard.aspx?FLOWFILENAME=FL\\BusinessCard&NAVMODE=Insert&FLNAVMODE=Submit");//&NAVMODE=Inset&FLNAVMODE=Submit
        }
        else if (e.CommandName == "cmdClientQuery")
        {
            string ss = this.ResolveUrl("..\\InnerPages\\FlowDesigner.aspx") + "?FLOWFILENAME=BusinessCard";
            Response.Write(" <script   language=javascript> window.open( '" + ss + " ','流程图','height=600,width=800,top=50,left=100,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no'); </script> ");
        }
    }


    protected void wgvMaster_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            string[] c = e.CommandArgument.ToString().Split(',');
            /*
             * 0、table 
             * 1、PK
             * 2、id
             * 3、WorkTime_AddUp where 
             * 4、WorkTime_OverTime2Rest where 
             * 5、WorkTime_YearHoliday where
             */
            object[] objParam = new object[]{"Services_BusinessCard","CardId",e.CommandArgument.ToString()," 1=0" ,
                " 1=0",
                " 1=0"};
            object[] myRet = Srvtools.CliUtils.CallMethod("SWorkTime", "InvalidWorkOnForm", objParam);
            ClientScript.RegisterStartupScript(GetType(), "", "alert('作废成功！');location.href='" + Request.Url.ToString() + "'", true);
        }
    }

    protected void wgvMaster_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView drv = (DataRowView)e.Row.DataItem;
            ImageButton imb = (ImageButton)e.Row.FindControl("del");

            if (drv["FlowFlag"].ToString() == "X" || drv["FlowFlag"].ToString() == "")//&&
            // Srvtools.CliUtils.fGroupID.IndexOf(System.Configuration.ConfigurationManager.AppSettings["FlowAdmin"].ToString()) != -1)
            {
                imb.CommandArgument = drv["CardId"].ToString();
                imb.CommandName = "del";
                imb.Attributes.Add("onclick", "return confirm('确认作废请假单" + drv["CardId"].ToString() + " ？')");
            }
            else
            {
                imb.Visible = false;
            }
        }

    }
}
